/**
   parts.cuh - Created by Timothy Morey on 8/15/2011.

   This file defines the device code for the particle simulator
 */

#ifndef __PARTS_CUH
#define __PARTS_CUH

#define THREADS_PER_BLOCK 512

#include <stdio.h>

#include "../common/cuda.cuh"

__global__ 
void UpdatePositionAndVelocity(DoF* X, DoF* Y, 
                               DoF* VX, DoF* VY, 
                               DoF* AX, DoF* AY, 
                               unsigned int n, float dt,
                               float minX, float maxX,
                               float minY, float maxY,
                               unsigned int minPart, unsigned int maxPart);

__global__
void UpdateAcceleration(DoF* X, DoF* Y, 
                        DoF* AX, DoF* AY,
                        unsigned int n,
                        float minX, float maxX,
                        float minY, float maxY,
			unsigned int minPart, unsigned int maxPart);

__global__ 
void UpdateVelocity(DoF* VX, DoF* VY, 
                    DoF* AX, DoF* AY,
                    float dt,
                    unsigned int minPart, unsigned int maxPart);

__global__
void CalculateMagnitude(DoF* VX, DoF* VY, DoF* VM,
                        unsigned int minPart, unsigned int maxPart);

__global__
void ClearFrame(unsigned char* frame, unsigned int width, unsigned int height,
                unsigned char r, unsigned char g, unsigned char b, unsigned char a);

__global__
void RenderFrame(unsigned char* frame, unsigned int width, unsigned int height,
                 DoF* X, DoF* Y, unsigned int n,
                 float minx, float maxx, float miny, float maxy);

__host__ 
__device__ 
DoF XDistanceTo(DoF x1, DoF x2, float minX, float maxX);

__host__ 
__device__ 
DoF YDistanceTo(DoF y1, DoF y2,	float minY, float maxY);

__host__ 
__device__ 
DoF DistanceTo(DoF x1, DoF y1, DoF x2, DoF y2, float minX, float maxX, float minY, float maxY);

__host__
__device__
void EnsureInBounds(DoF& x, DoF& y, float minX, float maxX, float minY, float maxY);

#endif
